<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<script src="${ctxStatic}/js/physical/physical.js"></script>
<script>
    $(function() {
        heBing("totalTable");
    });
    function cancelAudit(clinicId){
        delLoad('content','${ctx}/totalInspection/cancelAudit?clinicId='+clinicId+'&status=0','${ctx}/totalInspection/index?clinicId='+clinicId);
    }
    function print(id){
        printPdf('${ctx}/totalInspection/print?infoId='+id);
    }

    /*
     * 加载病种结果下拉框
     */
    $("input[name='aa']").select2({
        minimumInputLength: 1,
        multiple             : true,
        separator            : ";",
        initSelection        : function (element, callback) {   // 初始化时设置默认值
            $.ajax({
                url:"${ctx}/oper/diseaseManagement/automatic",
                data:{ids:element.val()},
                type: 'post', // 提交方式 get/post
                success:function(data){
                    var row = jQuery.parseJSON(data);
                    callback(row.items)
                }
            })
        },
        createSearchChoice   : function(term, data) {           // 创建搜索结果（使用户可以输入匹配值以外的其它值）
            return { id: term, text: term };
        },
        ajax : {
            url:"${ctx}/oper/diseaseManagement/automatic",              // 异步请求地址
            data: function (term) {
                return {
                    q: term
                };
            },
            results: function (data) {
                return {
                    results: data.items
                };
            }
        },
        formatSelection : resultFormatSelection,  // 选择结果中的显示
        formatResult    : resultFormatResult,
        escapeMarkup : function (m) { return m; }

    });
    function resultFormatResult(medata) {
        return medata.text;
    }
    var jy= "";
    var xj = "";
    function resultFormatSelection(medata) {
        xj="<div name='"+medata.id+"'>"+medata.text+"<div></br>"
        if(typeof(medata.jy)!="undefined"){
            jy= "<div name='"+medata.id+"'>"+medata.jy+"<div></br>";
        } else {
            jy="";
        }
        $("#jiankangjianyi").append(jy);
        $("#xiaojie").append(xj);
        return medata.text+"<input type='hidden' value='"+medata.id+"'/>";
    }

    // 移除完毕事件
    $("input[name='aa']").on("select2-removed", function(e) {
        $("#xiaojie").find("div[name='"+e.val+"']").remove();
        xj = $("#xiaojie").find("div").html();
        $("#jiankangjianyi").find("div[name='"+e.val+"']").remove();
        jy = $("#jiankangjianyi").find("div").html();
    })

    /**
     *列表保存
     * @param patientId
     * @param clinicId
     * @returns {boolean}
     */
    function addTreat(clinicId){
        var rows = $("#totalTable").find("tbody tr");
        if(rows.length >0){
            var text = "";
            var xiaojie = $("#xiaojie").html();
            var jianyi = $("#jiankangjianyi").html();
            var jiankangjianyi = $("#jiankangjianyi").html();
            var wenxintishi = $("#wenxintishi").html();
            for(var i=0;i<rows.length;i++){
                var row = rows.eq(i).find("td");
                var id = row.eq(1).find("input").val();
                var itemRange = row.eq(5).find("input").val();
                var jielun = row.eq(6).find("input").val();
                var fuzhen = row.eq(7).find("input").val();
//                var clinicId = row.eq(8).find("input").val();
                var itemResult="";
                var itemResults = row.eq(2).find("div ul li div");//项目结果
                if(itemResults.length>0){
                    for(var j=0;j<itemResults.length;j++){
                        itemResult += itemResults.eq(j).find("input").val()+";";//项目结果
                    }
                }

                text+="<tr><td>" +
                "<input type='hidden' name='itemList["+i+"].id'"+" value='"+id+"'/>" +
                "<input type='hidden' name='itemList["+i+"].itemResult'"+" value='"+itemResult+"'/>" +
                "<input type='hidden' name='itemList["+i+"].itemRange'"+" value='"+itemRange+"'/>" +
                "<input type='hidden' name='itemList["+i+"].jielun'"+" value='"+jielun+"'/>" +
                "<input type='hidden' name='itemList["+i+"].fuzhen'"+" value='"+fuzhen+"'/>" +

                "</td></tr>";
            }
            text+="<input type='hidden' name='bingzhong' value='"+xiaojie+"'/>" +
            "<input type='hidden' name='jianyi' value='"+jianyi+"'/>" ;
            var list = "<table>"+text+"</table>";
            $("#itemVoForm").html(list);
            var divUrl= '${ctx}/totalInspection/index?clinicId='+clinicId;
            $("#itemVoForm").ajaxSubmit({
                type: 'post', // 提交方式 get/post
                url:'${ctx}/totalInspection/save?status=1&clinicId='+clinicId, // 需要提交的 url
                success: function(data) { // data 保存提交后返回的数据，一般为 json 数据
                    if (data.code == "success") {
                        toastr.success(data.data);
                        loadDiv("content", divUrl);
                    } else if(data.code == 'info'){
                        loadDiv("content", divUrl);
                    } else {
                        flag = true;
                        toastr.error(data.data);
                    }
                }
            });
        } else{
            toastr.error("请选择提交项目后再保存");
            return false;
        }

    }




</script>
<form id="itemVoForm">

</form>
<div class="app">
    <section class="layout">
        <div class="content-wrap" id="content">
            <div class="wrapper" style="bottom: 50px;">
                <section class="panel panel-default">
                    <%--<form id="itemVoForm" method="post" onsubmit="return formSaveLoad('mainCenterDiv','itemVoForm','${ctx}/totalInspection/save?status=0','${ctx}/totalInspection/index?clinicId=${resultItem.clinicId}');" class="form-horizontal">--%>
                    <div class="panel-body">
                        <div class="col-lg-9" id="itemLeft">
                            <section class="panel  panel-default">
                                    <div class="datatable-top">
                                        <div class="pull-left">
                                            <input id="btnSubmit"  type="button" value="审核"
                                                   <c:choose>
                                                       <c:when test="${information.isOk ==0 || information.isOk eq '0'}">
                                                           class="btn btn-primary" onclick="addTreat('${resultItem.clinicId}')"/>
                                                       </c:when>
                                                       <c:otherwise>
                                                           disabled class="btn btn-default"/>
                                                       </c:otherwise>
                                                   </c:choose>
                                                   <%--<c:if test="${information.isOk !=0 || information.isOk != '0'}"> --%>
                                                   <%--<c:if test="${information.isOk ==0 || information.isOk eq '0'}"></c:if>/>--%>
                                            <input id="cancel"
                                                   <c:choose>
                                                       <c:when test="${information.isOk ==1 || information.isOk eq '1'}">
                                                           <%--class="btn btn-primary" onclick="confirmExtend('确认要取消审核该患者吗？',cancelAudit('${resultItem.clinicId}'))"--%>
                                                           class="btn btn-primary" onclick="cancelAudit('${resultItem.clinicId}')"
                                                       </c:when>
                                                       <c:otherwise>
                                                           disabled class="btn btn-default"
                                                       </c:otherwise>
                                                   </c:choose>
                                                   type="button" value="取消审核"/>
                                                   <%--<c:if test="${information.isOk ==1 || information.isOk eq '1'}"> disabled class="btn btn-default" onclick="confirmExtend('确认要取消审核该患者吗？',cancelAudit('${resultItem.clinicId}'))"</c:if>--%>
                                                    <%--<c:if test="${information.isOk !=0 || information.isOk != '0'}">  class="btn btn-primary" </c:if>  type="button" value="取消审核"/>--%>
                                            <input id="print" class="btn btn-primary" onclick="print('${information.id}')" type="button" value="打印"/>
                                        </div>
                                    </div>
                                    <table id="totalTable" class="table table-bordered mg-t datatable" style="width: 100%">
                                        <thead>
                                        <tr>
                                            <th>项目类型</th>
                                            <th>项目名称</th>
                                            <th>项目结果</th>
                                            <th>结果值</th>
                                            <th>项目单位</th>
                                            <th>范围</th>
                                            <th>结论</th>
                                            <th>复诊</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <c:forEach items="${list}" var="item" varStatus="index">
                                            <tr>
                                                <td>${item.parentItemName}<input value="${item.id}" type="hidden"/> </td>
                                                <td><input value="${item.id}" type="hidden"/>${item.itemName}</td>
                                                <td><input style="width: 200px;"  type="text" value="${item.itemResult}" name="aa"></td>
                                                <td>${item.unusual}</td>
                                                <td>${fns:getDictLabel(item.itemUnit,'SPEC_UNIT' , '')}</td>
                                                <td><input type="input" class="form-control"  value="${item.itemRange}"></td>
                                                <td><input type="input" class="form-control"  value="${item.jielun}"></td>
                                                <td><input type="checkbox"   value="${item.fuzhen}" <c:if test="${item.fuzhen==1 || item.fuzhen eq '1'}">checked</c:if>></td>
                                                <td><input type="hidden" class="form-control"  value="${item.clinicId}"></td>

                                            </tr>
                                        </c:forEach>
                                        </tbody>
                                    </table>


                            </section>

                        </div>
                        <div class="col-lg-3" id="itemRight">
                            <section class="panel  panel-default">
                                <header class="panel-heading">病种信息</header>
                                <div class="panel-body">
                                    <div id="rigthCenterDiv" >
                                        <%--<label>添加病种 ：</label>--%>
                                        <%--<div>--%>
                                            <%--<input class="form-control"  id="select"/>--%>
                                        <%--</div>--%>
                                            <label>小节 ：</label>
                                            <div>
                                                <div style="min-height: 200px;overflow-y:scroll; " contenteditable="true" htmlEscape="false"  id="xiaojie" name="bingzhong"
                                                     value="" class="form-control"></div>
                                            </div>

                                            <label>健康建议 ：</label>
                                            <div>
                                                <div style="min-height: 200px;overflow-y:scroll; " contenteditable="true" htmlEscape="false" id="jiankangjianyi"   name="jianyi"
                                                     value="${tResultOffice.jiankangjianyi}" class="form-control"></div>
                                            </div>
                                    </div>
                                </div>
                            </section>
                        </div>
                    </div>
                    <%--</form>--%>
                </section>
            </div>
        </div>
    </section>
</div>